package com.yang.mall.controller.admin;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yang.mall.dto.*;
import com.yang.mall.entity.OLResponse;
import com.yang.mall.entity.QueryRequest;
import com.yang.mall.service.IProductService;
import com.yang.mall.vo.ProductDetailVO;
import com.yang.mall.vo.ProductVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 商品库表 前端控制器
 * </p>
 *
 * @author hx
 * @since 2021-06-25
 */
@Api(tags = "【PC】商品模块")
@RestController
@RequestMapping("admin/product")
public class ProductAdminController {

    @Autowired
    private IProductService productService;

    @ApiOperation("添加或编辑商品")
    @PostMapping("createOrUpdate")
    public OLResponse createOrUpdate(@Valid @RequestBody CreateProductDTO product) {
        productService.createOrUpdate(product);
        return new OLResponse().success();
    }

    @ApiOperation("商品分页查询")
    @GetMapping("list")
    public OLResponse<IPage<ProductVO>> findPage(ProductDTO productDTO) {
        return new OLResponse().success(productService.findPage(productDTO));
    }

    @ApiOperation("商品列表")
    @GetMapping("queryList")
    public OLResponse<List<ProductVO>> queryList(ProductDTO productDTO) {
        return new OLResponse().success(productService.queryList(productDTO));
    }

    @ApiOperation("批量删除商品")
    @DeleteMapping("/deleteProductByIds")
    public OLResponse deleteProductByIds(@RequestBody ProductDTO productDTO) {
        productService.deleteProductByIds(productDTO.getProductIds());
        return new OLResponse().success();
    }

    @GetMapping("detail/{productId}")
    @ApiOperation("商品详情")
    public OLResponse<ProductDetailVO> detail(@PathVariable Long productId) {
        return new OLResponse().success(productService.detail(productId));
    }


}
